package org.inspiration.dudu.common.pojo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.inspiration.dudu.common.constant.Constant;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Result<T> {
    private Integer code;        // 状态码
    private String message;      // 提示消息
    private T data;              // 返回的数据

    // 成功的响应
    public static <T> Result<T> success(T data) {
        return new Result<>(Constant.SUCCESS_CODE, Constant.SUCCESS, data);
    }

    // 成功的响应，没有数据
    public static Result<Void> success() {
        return new Result<>(Constant.SUCCESS_CODE, Constant.SUCCESS, null);
    }

    // 失败的响应
    public static <T> Result<T> failure(Integer code, String message) {
        return new Result<>(code, message, null);
    }

    // 失败的响应，带有默认的错误信息
    public static <T> Result<T> failure(String message) {
        return new Result<>(Constant.SERVER_ERROR_CODE, message, null);
    }
}
